mui.init({
		swipeBack:true //启用右滑关闭功能
	});
mui(".mui-content").on("tap", "a", function() {
	var self = this;
	$("#inp11").val("");
	$("#inp12").val("");
	$("#timeTypeSelected").removeAttr("id").removeClass("mui-btn-primary");
	$(self).attr("id", "timeTypeSelected").addClass("mui-btn-primary");
	getRecords(1);
});
mui(".lcy-content").on("tap", "a", function() {
	var self = this;
	$("#tradeTypeSelected").removeAttr("id").removeClass("mui-btn-primary");
	$(self).attr("id", "tradeTypeSelected").addClass("mui-btn-primary");
	getRecords(1);
});
var requery = CmwMcore.$('btn_requery');
MeventMgr.onTouchstart(requery,function(event,self){
	getRecords(1);
	return false;
});
function getRecords(currentPage) {
	var tradeType, beginTime, endTime, timeType;
	beginTime = $("#inp11").val();
	endTime = $("#inp12").val();
//	if(beginTime && !CmwCore.isDate(beginTime)){
//		CmwDialog.failure({title:"友情提示",width:300,msg:"输入的起始日期格式不正确！"});
//		return;
//	}
//	if(endTime && !CmwCore.isDate(endTime)){
//		CmwDialog.failure({title:"友情提示",width:300,msg:"输入的截止日期格式不正确！"});
//		return;
//	}
	tradeType = $("#tradeTypeSelected").attr("data");
	if ($("#timeTypeSelected").length > 0) {
		timeType = $("#timeTypeSelected").attr("data");
	} else {
		timeType = "-1";
	}
	$("#begintime").val(beginTime);
	$("#endtime").val(endTime);
	$("#tradeType").val(tradeType);
	$("#timeType").val(timeType);
	$("#currentpage1").val(currentPage);
	 loadDatas();
//	document.getElementById("myform").submit();
}


mui.plusReady(function(){
	loadDatas();
	
});

function loadDatas(){
	var url = UrlConfig.userFund;
	var formData = $("#myform").serialize();
	MuiEventMgr.ajax(url,{pars:formData,
	  	sfn : function(data){
	  		callback(data);
	  	},ffn : function(err){
	  		mui.alert("获取数据失败：["+err+"]");
	  	}
	 });
}

function callback(data){	
	var accountinfoList = data.accountinfoList;
	if(typeof(accountinfoList) == 'undefined'){
		$("#item1_loanRecords").html("");
		$("#count").html("0");
		return;
	}

	if(!accountinfoList || accountinfoList.length == 0){
		$(".cmw_noinvest").show();
		$(".mui-loading").hide();
		return;	
	}
	
	$("#count").html(accountinfoList.length);
	var htmlArr = [];
	for(var i=0,count=accountinfoList.length; i<count; i++){
		var accountinfo = accountinfoList[i];
		var html = getHtml(accountinfo);
		htmlArr[i] = html;
	}
	var htmlCodes = htmlArr.join("  ");
	$("#item1_loanRecords").html(htmlCodes);

}

function getHtml(accountinfo){
	var time =accountinfo.time;
	var type = accountinfo.type;
	var num=accountinfo.num;
	var expenditureMoney =accountinfo.expenditureMoney; //支出
	var incomeMoney =accountinfo.incomeMoney;//收入
	var money =accountinfo.money; //余额
	var use = accountinfo.use;//说明

	var htmls = [
		'<li class="mui-table-view-cell">',
		'		<div>',
		'			<div class="cmw_list_row">',
		'				<div><span class="cell_label">日期：</span>'+time+'</div>',
		'				<div><span class="cell_label">类型：</span>'+type+'</div>',
		'			</div>',
		'			<div><span class="cell_label">支出金额：</span><span class="lcy_expenditure">￥'+expenditureMoney+'</span></div>',
		'			<div><span class="cell_label">收入金额：</span><span class="lcy_income">￥'+incomeMoney+'</span></div>',
		'			<div><span class="cell_label">余额：</span>￥'+money+'</div>',
		'			<div><span class="cell_label">说明：</span>'+use+'</div>',
		'		</div>',
		'	</li>'
	];
	
	return htmls.join(" ");
}
